package com.adnaan.backend;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

@MapperScan("com.adnaan.backend.mapper")
@SpringBootApplication
public class BackendApplication {

    public static void main(String[] args) {
        SpringApplication.run(BackendApplication.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(Environment env) {
        return args -> {
            String port = env.getProperty("server.port", "8080");
            String host = InetAddress.getLocalHost().getHostAddress();
            String contextPath = env.getProperty("server.servlet.context-path", "");
            String sysName = env.getProperty("system.name", "");
            String sysVersion = env.getProperty("system.version", "");

            System.out.println("\n----------------------------------------------------------");
            System.out.println("  " + sysName + sysVersion + "后端服务已启动! ");
            System.out.println("----------------------------------------------------------");
            System.out.println("  本地访问地址: \thttp://localhost:" + port + contextPath);
            System.out.println("  外部访问地址: \thttp://" + host + ":" + port + contextPath);
            System.out.println("  Swagger文档: \thttp://" + host + ":" + port + contextPath + "/doc.html");
            System.out.println("  数据库地址: \t" + env.getProperty("spring.datasource.url"));
            System.out.println("  Redis地址: \t" + env.getProperty("spring.data.redis.host") + ":" + env.getProperty("spring.data.redis.port"));
            System.out.println("----------------------------------------------------------");
            System.out.println("  作者：adnaan");
            System.out.println("  邮箱：1662877157@qq.com");
            System.out.println("  GitHub：https://github.com/adnaan-worker");
            System.out.println("  Gitee：https://gitee.com/adnaan");
            System.out.println("----------------------------------------------------------\n");
        };
    }
}
